//
//  FFPayOrderPriceView.m
//  FFMall
//
//  Created by ale tan on 2017/9/22.
//  Copyright © 2017年 IT.Bear. All rights reserved.
//

#import "FFPayOrderPriceView.h"

@interface FFPayOrderPriceView ()

@property (nonatomic ,strong)NSDictionary *prices;
@property (nonatomic ,strong)FBShippingWayModel *shippingWay;

@property (nonatomic ,strong)ConfirmPayOrder confirmPayOrderBlock;

@property (weak, nonatomic) IBOutlet UILabel *productPriceLabel;
@property (weak, nonatomic) IBOutlet UILabel *shippingPriceLabel;
@property (weak, nonatomic) IBOutlet UILabel *tripFeeLabel;
@property (weak, nonatomic) IBOutlet UILabel *totalPriceLabel;

@property (weak, nonatomic) IBOutlet NSLayoutConstraint *toBottom;

@end

@implementation FFPayOrderPriceView

+ (instancetype)priceViewWithPrices:(NSDictionary *)prices SelectedShippingWay:(FBShippingWayModel *)shippingWay{
    FFPayOrderPriceView *orderView = [[[NSBundle mainBundle] loadNibNamed:@"FFPayOrderPriceView" owner:nil options:nil] firstObject];
    orderView.prices = prices;
    orderView.shippingWay = shippingWay;
    return orderView;
}

- (void)show{
    UIView *view = [UIApplication sharedApplication].keyWindow.rootViewController.view;//[[UIApplication sharedApplication].delegate window];
    self.frame = view.bounds;
    [self layoutIfNeeded];
    [self updateDatas];
    [view addSubview:self];
}

- (void)awakeFromNib{
    [super awakeFromNib];
    
    _toBottom.constant = isDeviceIphoneX?34:0;
}

- (void)setConfirmPayOrder:(ConfirmPayOrder)confirmPayOrder{
    _confirmPayOrderBlock = confirmPayOrder;
}

- (void)updateDatas{
    NSString *currencyLogo = @"¥";
//    if (_prices[@"currencyLogo"]) {
//        currencyLogo = _prices[@"currencyLogo"];
//    }
    _productPriceLabel.text = [NSString stringWithFormat:@"%@%@",currencyLogo,_prices[@"productAmount"]];
    _shippingPriceLabel.text = [NSString stringWithFormat:@"¥%@",_prices[@"deliveryFee"]];
    _tripFeeLabel.text = [NSString stringWithFormat:@"¥%@",_prices[@"totalServicePrice"]];
    _totalPriceLabel.text = [NSString stringWithFormat:@"¥%.2f",[_prices[@"amountPayable"] floatValue]];
}

#pragma mark -Events-
- (IBAction)clickToCancle:(id)sender {
    [self removeFromSuperview];
    if (_confirmPayOrderBlock) {
        _confirmPayOrderBlock(NO);
    }
}

- (IBAction)clickBackgroundToCancle:(id)sender {
    [self removeFromSuperview];
}

- (IBAction)clickToConfirmPayOrder:(id)sender {
    [self removeFromSuperview];
    if (_confirmPayOrderBlock) {
        _confirmPayOrderBlock(YES);
    }
}
@end
